import { cloneDeep } from "lodash";
const DEFAULTSTATE = {
  manInfo: {
    name: "小溪流",
    sex: "男",
    money: 1000,
    classes: "大一",
    jiJie: ["春", "夏", "秋", "冬"],
    objes: {
      succeed: "成功",
      failed: "失败",
    },
  },
};

export default {
  namespaced: true,
  state: {
    ...cloneDeep(DEFAULTSTATE),
  },
  getters: {
    name: (state) => state.manInfo.name || cloneDeep(DEFAULTSTATE.manInfo.name),
    sex: (state) => state.manInfo.sex || cloneDeep(DEFAULTSTATE.manInfo.sex),
    money: (state) =>
      state.manInfo.money || cloneDeep(DEFAULTSTATE.manInfo.money),
    classes: (state) =>
      state.manInfo.classes || cloneDeep(DEFAULTSTATE.manInfo.classes),
    jiJie: (state) =>
      state.manInfo.jiJie || cloneDeep(DEFAULTSTATE.manInfo.jiJie),
    objes: (state) =>
      state.manInfo.objes || cloneDeep(DEFAULTSTATE.manInfo.objes),
  },
  mutations: {
    set_name(state, payload) {
      state.manInfo.name = payload;
    },
    set_money(state, payload) {
      state.manInfo.money = payload;
    },
  },
  actions: {
    async get_manInfo({ commit, state }, params) {
      const res = await new Promise((resolve, reject) => {
        let num = Math.floor(Math.random() * 10);
        resolve(num);
      }).then((result) => {
        return result;
      });
      let initNum = state.manInfo.money;
      initNum += res;
      commit("set_money", initNum);
    },
  },
};
